const fs = require("fs");
const csvParser = require("csv-parser");
const http = require("http");

const results = [];
for (let groupNum = 5; groupNum <= 5; groupNum++) {
  fs.createReadStream(`./lubang${groupNum}.csv`)
    .pipe(csvParser())
    .on("data", (row) => {
      results.push(row);
    })
    .on("end", () => {
      results.forEach((item, index) => {
        const noise = [
          1, 2, 3, 4, 5, 6, 7, 8, 8.95, 9, 9.05, 9.1, 9.15, 9.2, 9.25, 9.3,
          9.35, 9.4, 9.45, 9.5, 9.55, 9.6, 9.65, 9.7, 9.75, 9.8, 9.85,
        ];
        const req = http.request("http://localhost:3000/api/validation", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
        });
        const name = `exp${groupNum}_${noise[index] * 2}`;
        // const name = `真实测试_${noise[index] * 2}`;
        const group = `test${groupNum}`;

        req.write(
          JSON.stringify({
            name,
            group,
            virtual: "true",
            noise: noise[index] * 2,
            indicator1: item["mAP_0.5"],
            indicator2: item["mAP_50_95"],
          })
        );
        req.end();
      });
    });
}
